package swordoffer.offer05;

public class IfInputTypeIsString_Char {
    public String replaceSpace(String s) {
        int length = s.length();
        int spaceNum = 0;
        for (int i = 0; i < length; i++) {
            if (s.charAt(i) == ' ') {
                spaceNum++;
            }
        }
        char[] res = new char[length + 2 * spaceNum];
        int count = 0;
        for (int i = 0; i < length; i++) {
            char ch = s.charAt(i);
            if (ch == ' ') {
                res[count++] = '%';
                res[count++] = '2';
                res[count++] = '0';
            } else {
                res[count++] = ch;
            }
        }
        return new String(res, 0, count);
    }
}
